// SPDX-License-Identifier: Mulan PSL v2
/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This software is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

use thiserror::Error;

#[derive(Error, Debug)]
pub enum ShmemTransportError {
    // (Low-level errors during shmem creation or opening)
    #[error("Failed to create shmem '{name}': {error}")]
    ShmemCreateError {
        name: String,
        #[source]
        error: std::io::Error,
    },

    #[error("Failed to open shmem '{name}': {error}")]
    ShmemOpenError {
        name: String,
        #[source]
        error: std::io::Error,
    },

    // (Errors related to the connection's state or lifecycle)
    #[error("Connection timed out")]
    ConnectTimeout,

    #[error("Connection is closed")]
    ConnectionClosed,

    // (Errors during an active read/write operation on an established connection)
    #[error("Read operation timed out")]
    ReadTimeout,

    #[error("Write buffer overflow (attempted: {attempted}, capacity: {capacity})")]
    ReadOverflow { attempted: usize, capacity: usize },

    #[error("Write operation timed out")]
    WriteTimeout,

    #[error("Write buffer overflow (attempted: {attempted}, capacity: {capacity})")]
    WriteOverflow { attempted: usize, capacity: usize },
}
